package com.yang.service;

import com.yang.entity.Cost;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class CostService {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    public void saveBatch(List<Cost> list) {
        jdbcTemplate.execute("delete from cost");
        for (Cost cost : list) {
            String id= UUID.randomUUID().toString();
            String insertSql=" insert into cost ( id, to_where, type , first_weight, first_price, add_price ,hour,remark) values (";
            insertSql=insertSql+"'"+id+"',"+"'"+cost.getToWhere()+"',"+"'"+cost.getType()+"',"+cost.getFirstWeight()+","
                    +cost.getFirstPrice()+","+cost.getAddPrice()+","+"'"+cost.getHour()+"',"+"'"+cost.getRemark()+"')";
            System.out.println(insertSql);
            jdbcTemplate.execute(insertSql);
        }
    }
}
